package com.iweb.newa202104.service.impl;

import com.iweb.newa202104.Mapper.DurationMapper;
import com.iweb.newa202104.dto.DurationOutputDTO;
import com.iweb.newa202104.entity.*;
import com.iweb.newa202104.service.DurationService;
import com.iweb.newa202104.util.CommonUtil;
import com.iweb.newa202104.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.Duration;

/**
 * @Author: LGZ
 * @Date: 2021/5/12 16:37
 * @Description:
 */
@Service
public class DurationServiceImpl implements DurationService {

    @Autowired
    DurationMapper durationMapper;

    @Override
    public ResultVO getAllByCategory(int categoryId) {
        ResourceEntity resourceEntity = new ResourceEntity();
        resourceEntity.setCategoryId(categoryId);
        return CommonUtil.ajaxReturn(durationMapper.getAllByCategory(resourceEntity));
    }

    @Override
    public ResultVO getAllByResource(int resourceId) {
        ResourceEntity resourceEntity = new ResourceEntity();
        resourceEntity.setResourceId(resourceId);
        return CommonUtil.ajaxReturn(durationMapper.getAllByResource(resourceEntity));
    }

    @Override
    public ResultVO getAll() {
        return CommonUtil.ajaxReturn(durationMapper.getAll());
    }

    @Override
    public ResultVO getAllByUser(int userId) {
        UserEntity userEntity = new UserEntity();
        userEntity.setUserId(userId);
        return CommonUtil.ajaxReturn(durationMapper.getAllByUser(userEntity));
    }

    @Override
    public ResultVO getUserResource(int userId, int resourceId) {
        DurationEntity durationEntity = new DurationEntity();
        durationEntity.setUserId(userId);
        durationEntity.setResourceId(resourceId);
        return CommonUtil.ajaxReturn(durationMapper.getUserResource(durationEntity));
    }

    @Override
    public ResultVO getUserCategory(int userId, int categoryId) {
        QuestionEntity questionEntity = new QuestionEntity();
        questionEntity.setUserId(userId);
        questionEntity.setCategoryId(categoryId);
        return CommonUtil.ajaxReturn(durationMapper.getUserCategory(questionEntity));
    }
}
